var loginObj = {
    lTeamId: "",
    ownerUserid: "",
    vcodeFlage: 1,
    init: function() {
        this.lTeamId = publicObj.getUrlData("lTeamId");
        this.hideLoginBox();
        this.getVcode();
        this.login();
    },
    //隐藏登录框
    hideLoginBox: function() {
        $(".n_l_dele").bind("click", function() {
            $(".normallogin").hide();
            $(".layerbox").hide();
        })
    },
    getVcode: function() {
        var me = this;
        $(".checkboxtxt1").bind("click", function() {
            $(".n_l_errtip").html("");
              var userid = $(".n_l_mob").val();
            if (userid == "") {
                $(".n_l_errtip").html("请输入手机号");
                return false;
            }
            if (me.vcodeFlage == 1) {
                me.vcodeFlage = 2;
                var urlStr = magic_config.urlPrefix + 'UserWebService/setCheckcode';
                var dataObj = {
                    userId: userid
                }
                $.ajax({
                    url: urlStr,
                    type: 'get',
                    data: dataObj,
                    dataType: 'json',
                    success: function(res) {
                        var nCode = res.return.nCode;
                        if (nCode === 0) {
                            $(".checkboxtxt1").hide();
                            $(".checkboxtxt2").show();
                            me.vcodeFlage = 1;
                            me.countDown();
                        } else {
                            $(".n_l_errtip").html(res.return.strText);
                        }
                    },
                    error: function(res) {
                        console.log("数据请求失败，前到后");
                    }
                });
            }

        })
    },
    //倒计时
    countDown: function() {
        var time = 60;
        var interval = setInterval(function() {
            if (time <= 0) {
                time = 60;
                $(".checkboxtxt2").html(time + 's');
                $(".checkboxtxt1").show();
                $(".checkboxtxt2").hide();
                clearInterval(interval);

            } else {
                time -= 1;
                $(".checkboxtxt2").html(time + 's');
            }
        }, 1000);
    },
    login: function() {
        var me = this;
        $(".n_l_btn").bind("click", function() {
            var urlStr = magic_config.urlPrefix + 'UserWebService/rueMallWxRegLogin';
            $(".n_l_errtip").html("");
            var userid = $(".n_l_mob").val();
            var vcode = $(".n_l_checkcode ").val();
            console.log(userid);
            if (userid == "") {
                $(".n_l_errtip").html("请输入手机号");
                return;
            }
            if (vcode == "") {
                $(".n_l_errtip").html("请输入验证码");
                return;
            }
            var dataObj = {
                userId: userid,
                checkCode: vcode,
                openId: sessionStorage.getItem("openId")
            }
            console.log(dataObj);
            $.ajax({
                url: urlStr,
                type: 'get',
                data: dataObj,
                dataType: 'json',
                success: function(res) {
                    var nCode = res.return.nCode;
                    if (nCode === 0) {
                        $.cookie("userid", res.response.userId, {　　
                            path: "/",
                            expires: 7
                        })
                        $(".normallogin").hide();
                        $(".layerbox").hide();
                        statusCheckObj.init(1);
                    } else {
                        $(".n_l_errtip").html(res.return.strText);
                        console.log("数据请求失败，后到前");
                    }
                },
                error: function(res) {
                    console.log("数据请求失败，前到后");
                }
            });
        })
    },
};
loginObj.init();